package com.scisoft.scan.control.quickcheck;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.scisoft.scan.data.quickcheck.QuickCheckDetailBean;
import com.scisoft.scan.dy.R;
import com.squareup.picasso.Picasso;

import java.util.List;

public class QuickCheckAdapter extends BaseAdapter {
    private List<QuickCheckDetailBean> quickCheckDetailBeanList;//数据源
    private LayoutInflater mInflater;//布局装载器对象
    private Context mContext;

    public QuickCheckAdapter(List<QuickCheckDetailBean> quickCheckDetailBeanList, Context context) {
        this.quickCheckDetailBeanList = quickCheckDetailBeanList;
        mContext = context;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        //return返回的是int类型，也就是页面要显示的数量。
        return quickCheckDetailBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return quickCheckDetailBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        //将布局文件转化为View对象
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_quickcheck_check, null);
        }
        TextView tv_partNo = convertView.findViewById(R.id.tv_partNo);
        TextView tv_partName = convertView.findViewById(R.id.tv_partName);
        TextView tv_supplierName = convertView.findViewById(R.id.tv_supplierName);
        TextView tv_ycj = convertView.findViewById(R.id.tv_ycj);
        TextView tv_kcs = convertView.findViewById(R.id.tv_kcs);
        TextView tv_sps = convertView.findViewById(R.id.tv_sps);
        TextView tv_ck = convertView.findViewById(R.id.tv_ck);
        TextView tv_hj = convertView.findViewById(R.id.tv_hj);
        ImageView iv_img = convertView.findViewById(R.id.iv_img);
        //获取相应索引的ItemBean对象
        QuickCheckDetailBean bean = quickCheckDetailBeanList.get(position);
        //设置控件的对应属性值
        tv_partNo.setText(bean.partCode);
        tv_partName.setText(bean.partName);
        tv_supplierName.setText(bean.manufacturerName);
        tv_kcs.setText(String.valueOf(bean.stockCount));
        tv_sps.setText(String.valueOf(bean.checkCount));
        tv_ck.setText(bean.depotName);
        tv_hj.setText(bean.position);
        if (bean.imgUrl != null && !bean.imgUrl.equals("")) {
            Picasso.with(mContext).load(bean.imgUrl).into(iv_img);
        } else {
            iv_img.setImageDrawable(convertView.getResources().getDrawable(R.drawable.ic_noimage));
        }
        return convertView;
    }
}
